local DEFAULT_FONT = STANDARD_TEXT_FONT
local NEW_FONT = "Interface\\Addons\\jerry\\font.ttf"

local replaced, called
local function ReplaceFont(default, repl, object)
	if
		type(object) ~= "table" or
		type(object.IsObjectType) ~= "function" or
		object:IsObjectType"SimpleHTML"
	then
		return false
	end
	if object.GetFont then
		called = called + 1
		local font, size, flags = object:GetFont()
		if font == default then
			object:SetFont(repl, size, flags)
			replaced = replaced + 1
		end
	end
	return true
end

local function ReplaceAllFonts(default, repl, ...)
	for i = 1, select("#", ...) do
		local object = select(i, ...)
		if not ReplaceFont(default, repl, object) then return end
		if object:IsObjectType("Frame") and (not object:IsProtected() or not InCombatLockdown()) then
			ReplaceAllFonts(default, repl, object:GetRegions())
			ReplaceAllFonts(default, repl, object:GetChildren())
		end
	end
end

SlashCmdList.JERRY_FONTSWITCH = function (input)
	replaced, called = 0, 0
	if input == "new" then
		ReplaceAllFonts(DEFAULT_FONT, NEW_FONT, UIParent)
	else
		ReplaceAllFonts(NEW_FONT, DEFAULT_FONT, UIParent)
	end
	DEFAULT_CHAT_FRAME:AddMessage(string.format("Replaced %d/%d element", replaced, called))
end
SLASH_JERRY_FONTSWITCH1="/jfs"
